package com.iot.ic.modules.service.impl;

import com.iot.ic.modules.dao.AmountDao;
import com.iot.ic.modules.dao.UserDao;
import com.iot.ic.modules.model.Accounts;
import com.iot.ic.modules.model.Amounts;
import com.iot.ic.modules.model.User;
import com.iot.ic.modules.service.AmountService;
import com.iot.ic.modules.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("amountService")
public class AmountServiceImpl extends BaseServiceImpl implements AmountService {
    @Autowired
    private AmountDao amountDao;


    @Override
    public Amounts findAmountByUid(Integer userId) throws Exception {
        return amountDao.findAmountByUid(userId);
    }

    @Override
    public Amounts updateAmountState(Integer userId, Integer state) throws Exception {
        if (amountDao.updateAmountState(userId, state)) {
            return amountDao.findAmountByUid(userId);
        } else {
            return null;
        }
    }

    @Override
    public List<Accounts> findAccountByUid(Integer userId) throws Exception {
        return amountDao.findAccountByUid(userId);
    }

    @Override
    public Accounts saveOrUpdateObject(Accounts accounts) throws Exception {
        return (Accounts) amountDao.addOrUpdateObject(accounts);
    }

}
